#ifndef _NETWORK_SERVER_HPP
#define _NETWORK_SERVER_HPP

#include "UDTInitializer.hpp"
#include <vector>
#include "Packet.hpp"
#include "Network.hpp"
#include "Event.hpp"
#include <thread>
#include <chrono>

namespace phx
{

class NetworkServer
{
public:
	static const unsigned int MAX_BUFFER_SIZE = 100000;
	NetworkServer(const char *ipAddress, unsigned short port, NetworkType networkType = NetworkType::Reliable, int maxConnections = 32);
	void accept();
	void send(const char *data, int size);
	void send(Packet &packet);
	void receive();
	void close();

	inline bool isStarted(){ return mStarted; }
	~NetworkServer();
private:
	UDTSOCKET mSocket;
	sockaddr_in mMy_addr;
	std::vector<UDTSOCKET*> mUdtSocketClients;
	NetworkType mNetworkType;
	bool mStarted;
	std::thread *mThread;
	char mReceivedData[MAX_BUFFER_SIZE];
};

}

#endif